package com.woniuxy.light_smart.service.imp;


import com.woniuxy.light_smart.dto.AreaDto;
import com.woniuxy.light_smart.entity.ApplicationRole;
import com.woniuxy.light_smart.entity.Area;
import com.woniuxy.light_smart.entity.Role;
import com.woniuxy.light_smart.mapper.AreaMapper;
import com.woniuxy.light_smart.mapper.RoleMapper;
import com.woniuxy.light_smart.mapper.UserMapper;
import com.woniuxy.light_smart.service.AreaService;
import com.woniuxy.light_smart.vo.AreaCountVo;
import com.woniuxy.light_smart.vo.AreaRoleVo;
import com.woniuxy.light_smart.vo.AreaVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {
    @Resource
    private AreaMapper areaMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<Area> getAll() {
        return areaMapper.getAll();
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return areaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Area record) {
        return areaMapper.insert(record);
    }

    @Override
    public int insertSelective(Area record) {
        return areaMapper.insertSelective(record);
    }

    @Override
    public Area selectByPrimaryKey(Long id) {
        return areaMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Area record) {
        return areaMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Area record) {
        return areaMapper.updateByPrimaryKey(record);
    }

    //    带分页和模糊查询的查全部区域
    @Override
    public List<Area> selectAll2(AreaDto areaDto) {
        return areaMapper.selectAll2(areaDto);
    }

    @Override

    public List<Area> selectAllArea() {
        return areaMapper.selectAllArea();
    }
    public  List<AreaVo> selectAllUser() {

        return areaMapper.selectAllUser();
    }

    @Override
    public List<Role> selectAllRole() {
        return areaMapper.selectAllRole();
    }

    @Override
    public List<AreaCountVo> selectAllUserCounte() {
        return areaMapper.selectAllUserCount();

    }



    @Override
    public List<Area> selectExportData(AreaDto area) {
        return areaMapper.selectExportData(area);
    }

    @Override
    public List<AreaRoleVo> selectAllRoleAndArea() {
        List<Area> areaList = areaMapper.selectAllArea();
        List<Role> roleList = areaMapper.selectAllRole();
        List<AreaRoleVo> areaRoleVos=new ArrayList();
        AreaRoleVo areaRoleVo = new AreaRoleVo();
        areaRoleVo.setAreas(areaList);
        areaRoleVo.setRoles(roleList);
        areaRoleVos.add(areaRoleVo);
        return areaRoleVos;
    }

    @Override
    public List<Integer> selectAllOneRole(Integer userId, Integer areaId) {

        List<AreaCountVo> areaCountVos = areaMapper.selectAllOneRole(userId, areaId);

        List<Integer> integers=new ArrayList<>();
        if(areaCountVos.size()!=0){
           for (int i=0;i<areaCountVos.size();i++){
               integers.add(areaCountVos.get(i).getRoleId());

           }
       }
        return integers;
    }

    @Override
    public List<AreaVo> selectAllOne(Integer userId, Integer areaId) {
        return areaMapper.selectAllOne(userId,areaId);
    }


}
